package com.newer.his.BasicData.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.newer.his.common.entity.Medicine;
import com.newer.his.common.mapper.MedicineMapper;


/**
 * 药品信息 控制器
 * 
 *
 */

@RestController
@RequestMapping("/medicine")
public class MedicineController {

	@Autowired
	MedicineMapper mapper;
	
	
	@GetMapping
	public List<Medicine> getAllMedicine() {
		return mapper.findAll();
		
	}
	@GetMapping("/{id}")
	public Medicine  getMedicineById(@PathVariable int id) {
		return mapper.findById(id);
		
	}

	 @PostMapping
	public Medicine addMedicine(Medicine medicine) {
		mapper.save(medicine);
		return medicine;
		
	}
	 @PutMapping("/{id}")
	public  void updateMedicine(@PathVariable int id,
			@RequestBody Medicine medicine) {
		medicine.setId(id);
		mapper.update(medicine);
		
	}
	 @DeleteMapping("/{id}")
	public  void deleteMedicine(@PathVariable int id) {
		mapper.delete(id);
		
		
		
	}
	
	
	
	
	
}
